package com.youlu.campus.common.utils.excel;


import com.alibaba.excel.EasyExcelFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Slf4j
public class ExcelUtils<T> {

    public List<T> readExcel(MultipartFile file, Class clazz) {
        try {
            log.info("file name - > {}",file.getOriginalFilename());
            ExcelListener<T> excelListener = new ExcelListener<>();
            EasyExcelFactory.read(file.getInputStream(), clazz, excelListener).sheet().headRowNumber(1).doRead();
            return excelListener.getDataList();
        } catch (IOException e) {
            e.printStackTrace();
            log.error(" excel error ->",e);
        }catch (Exception e) {
            e.printStackTrace();
            log.error(" excel error ->",e);
        }
        return null;
    }


}
